<?php
namespace Plug\defend\action;

use Plug\Action;
use Plug\defend\model\DomainPlugModel;

class DefendPlugAction extends Action
{
    private $Domian = null;

    public function __construct()
    {
        $this->Domian = new DomainPlugModel();
    }

    /**
     * 获取一个域名
     */
    public function getDomain()
    {
        $_domains = $this->Domian->findAll(array('id !='=>0),array('domain'));
        if(count($_domains)>0){
            $_domain = $_domains[array_rand($_domains,1)];
            $_query = $_SERVER['QUERY_STRING'];
            return array('domain'=>$_domain['domain'],'url'=>urldecode($_domain['domain'].$_SERVER['PHP_SELF'].'?defend_jump=1&'.$_query));
        }else{
            return false;
        }
    }
}
